package edu.whu.rose.clock.kps.algorithm.blinks.index;

import java.util.HashSet;
import java.util.Iterator;

import edu.whu.rose.clock.ssql.util.ExpandableIntArray;
import edu.whu.rose.clock.ssql.util.SequentialIntArray;

public class Block {

	private int id;
	
	private HashSet<Integer> vertexes;
	private ExpandableIntArray[] edges;
	private HashSet<Integer> portals;
	
	public Block(int id) {
		this.id = id;
		vertexes = new HashSet<Integer>();
		edges = new ExpandableIntArray[2];
		edges[0] = new ExpandableIntArray();
		edges[1] = new ExpandableIntArray();
		portals = new HashSet<Integer>();
	}
	
	public void addVertex(int vertex) {
		vertexes.add(new Integer(vertex));
	}
	
	public void addEdge(int source, int end) {
		edges[0].add(source);
		edges[1].add(end);
	}
	
	public void addPortal(int portal) {
		portals.add(new Integer(portal));
	}
	
	public int size() {
		return vertexes.size();
	}
	
	public int[] getVertexes() {
		SequentialIntArray result = new SequentialIntArray(vertexes.size());
		Iterator<Integer> it = vertexes.iterator();
		int i = 0;
		while (it.hasNext()) {
			result.insert(it.next().intValue());
			i++;
		}
		return result.getArray();
	}
	
	public int getId() {
		return id;
	}

	public int[] getStartVertexes() {
		return edges[0].toArray();
	}
	
	public int[] getEndVertexes() {
		return edges[1].toArray();
	}
	
	public HashSet<Integer> getPortals() {
		return portals;
	}

	public int edgeNum() {
		return edges[0].getSize();
	}
}
